package com.neuedu.it.newidea.config;

import com.neuedu.it.newidea.web.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(new JwtInterceptor())
                .addPathPatterns("/ai/**")
                .addPathPatterns("/creation/**")
                .addPathPatterns("/ai/school-activities/upload")
                .addPathPatterns("/mycreation/**")
                .addPathPatterns("/ai/chat-stream")
                .excludePathPatterns("/creation/detail/**")
                .excludePathPatterns("/creation/list")
                .excludePathPatterns("/ai/imgstatus/**")
                .excludePathPatterns("/ai/search");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/ss/imgs/**")
                .addResourceLocations("file:D:/java/images");
    }
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*");
    }
}